/**
 * Created by LUOLIANG on 2016/6/20.
 */
var productlist = avalon.define({
    $id: "productlistController",
    pageSize: 6,
    pageCurrent: 1,
    pageTotle: 0,
    productlist: {},
    keyword: "",
    money: "",
    user: "",
    productid: "",
    statisData: {
        total: 0,
        profit: 0
    },

    loadproduct: function () {
        productlist.userInfo();
        productlist.statistics();
        $.ajax({
            type: 'POST',
            url: '/CounterDrops/product/getproductlist',
            data: {
                pageSize: productlist.pageSize,
                pageCurrent: productlist.pageCurrent,
                keyword: productlist.keyword
            },
            success: function (data) {
                productlist.productlist = data.model.results;
                productlist.pageTotle = data.model.totalPage;
            },
        })
    },

    detail: function (id) {
        $("#product").addClass('hide');
        $("#moneyform").removeClass('hide');
        productlist.productid = id;
    },

    userInfo: function () {
        $.ajax({
            type: "post",
            url: "/CounterDrops/weuser/currentUser",
            data: {},
            success: function (data) {
                if (data.success == true) {
                    productlist.user = data.model;
                } else {
                    toastr.warning(data.msg);
                }
            }
        });
    },

    statistics: function () {
        $.ajax({
            type: "get",
            url: "/CounterDrops/weProduct/Statistics",
            data: {},
            success: function (data) {
                if (typeof(data.model) != 'undefined') {
                    productlist.statisData = data.model;
                }
            }
        });
    },

    pay: function () {
        $.ajax({
            type: "get",
            url: "/CounterDrops/weProduct/payProduct",
            data: {
                productid: productlist.productid,
                money: productlist.money
            },
            success: function (data) {
                if (data.success == true) {
                    toastr.info(data.msg);
                    setTimeout(window.location.reload(), 2000);
                } else {
                    toastr.error(data.msg);
                }
            }
        });
    }
});
productlist.loadproduct();